#modeltag({tagcode:"jxbrms_systemreportinfo",id:params[0]})
#modeltag({tagcode:"jxbrms_systemreportinfoext",id:params[0]})
#include("/common/layout/bootstrap_form_layout.html")
#@layout()
#define title()
#(jxrb.message(actionName,"queryCommon")) #(systemreportinfo.report_name ??)
#end
#define head()
<style type="text/css">
	.table {table-layout:fixed;word-break:break-all;}
</style>
#jx_css({file:"plugins/bootstrap-table/bootstrap-table.min.css"})
#jx_css({file:"plugins/chosen/chosen.min.css"})
<script language="javascript">
  seajs.use(['jquery', 'jx_msgbox', "jcs","jx_check", "json2"], function ($, msgbox,jcs)
  {
    $(function ()
    {
      if ("#(action)" != "added") {
        $("#reportCode").attr("readonly", "readonly");
        $("#reportCode").addClass("readonly_input");
      }
      $(document).on("click", "#b_submit", function ()
      {
        if ($("#queryFlagCheck").is(':checked'))
          $("#queryFlag").val("7");
        else
          $("#queryFlag").val("6");
        if ($("#loginFlagCheck").is(':checked'))
          $("#loginFlag").val("1");
        else
          $("#loginFlag").val("0");
        if (!createData())
        {
          alert("必须有字段信息！");
          return false;
        }
        if (!jxCheck.check())
          return false;

        var j_ext3 = {};
        $("input,textarea").each(function ()
        {
          if ((undefined != $(this).attr("id")) && (undefined != $(this).attr("ext3")))
          {
            j_ext3[$(this).attr("id")] = $(this).val();
          }
        });
        
        $("#ext3_value").val(JSON.stringify(j_ext3));
        msgbox.alert({url: "#(controllerKey)#(action)/"},
                function ()
                {
                  if (msgbox.messageType != 2)
                    returnInfo();
                  msgbox.close() ;
                });
      });

      $(document).on("click", "#b_return", function ()
      {
        returnInfo();
      });

      $(document).on("click", "#ck_all", function ()
      {
        var ckFlag = $(this).is(":checked");
        $("#fieldinfo_tab").find("[id='ck_field']").each(function ()
        {
          $(this).attr("checked", ckFlag);
        });
      });

      var tpw;
      function initTpw()
      {
        tpw = $(window.top.document).find("#tab_fieldinfo");
        if (tpw.length == 0)
          tpw = $(window.document).find("#tab_fieldinfo");
      }
      function tpwclose()
      {
        initTpw();
        tpw.find("div").each(function ()
        {
          if ((undefined != $(this).attr("id")) && (!$(this).is(":visible")))
          {
            $(this).remove();
          }
        });
      }
      function setFieldInfo(l_field)
      {
        var fValue;
        tpw.find("input,select,textarea").each(function ()
        {
          if (undefined != $(this).attr("name"))
          {
            l_field.find("[name='" + $(this).attr("name") + "']").val($(this).val());
            if ($(this).attr("name") == "SRFI.field_type")
            {
              l_field.find("#fieldType").html($(this).find("option:selected").text());
              if (($(this).val() == "ldate") || ($(this).val() == "sdate"))
                l_field.find("#div_f_date").show();
              else if ($(this).val() == "dictselect")
                l_field.find("#div_f_dictselect").show();
              else if ($(this).val() == "sqlselect")
                l_field.find("#div_f_sqlselect").show();
              else if ($(this).val() == "tagselect")
                l_field.find("#div_f_tagselect").show();
              else if ($(this).val() == "uddt")
                l_field.find("#div_f_uddt").show();
              else if ($(this).val() == "d")
                l_field.find("#div_f_d").show();
            }
          } else if (undefined != $(this).attr("ext"))
          {
            fValue = $(this).val();
            l_field.find("[ext='" + $(this).attr("ext") + "']").each(function ()
            {
              $(this).val(fValue);
            });
            l_field.find("[ext2='" + $(this).attr("ext") + "']").each(function ()
            {
              $(this).html(fValue);
            });
          } else if (undefined != $(this).attr("ctag"))
          {
            fValue = $(this).is(':checked');
            l_field.find("[ctag='" + $(this).attr("ctag") + "']").each(function ()
            {
              $(this).attr("checked", fValue);
            });
          }
        });
      } 
      $(document).on("click", "#fieldAdd", function ()
      {
        var l_field;
        var fValue;
        msgbox.alert({url: "#(controllerKey)?html=fieldInfo", area: "600px", type: "get"}, function ()
        {
          tpwclose();
          $.get("#(controllerKey)?html=fieldNext", function (data)
          {
            $("#fieldinfo_tab").append(data);
            l_field = $("#fieldinfo_tab").find("tr:last");
			 
            setFieldInfo(l_field);
          });
          msgbox.close();
        });
      });
      function getCheckedCount()
      {
        var chkCount = 0;
        
        $("#fieldinfo_tab").find("[id='ck_field']").each(function()
        {
          if ($(this).is(":checked"))
          {
            chkCount ++ ;
          }
        });
        return chkCount ;
      }
      $(document).on("click", "#fieldEdit", function ()
      {
				if (getCheckedCount() <=0)
				{
					msgbox.alert({content:'没有选中要修改的字段！'});
					return ;
				}
        var l_field;
        $("#fieldinfo_tab").find("[id='ck_field']").each(function()
        {
          if ($(this).is(":checked"))
          {
            l_field = $(this).parent().parent();
            return false ;
          }
        });
        msgbox.alert({url: "#(controllerKey)?html=fieldInfo", area: "600px", type: "get"}, function ()
        {
          tpwclose();
          setFieldInfo(l_field);
          msgbox.close();
        }, function ()
        {
          initTpw();
          l_field.find("input,textarea").each(function ()
          {
            if (undefined != $(this).attr("name"))
            {
              tpw.find("[name='" + $(this).attr("name") + "']").val($(this).val());
              if ($(this).attr("name") == "SRFI.field_type")
              {
                if (($(this).val() == "ldate") || ($(this).val() == "sdate"))
                  tpw.find("#div_f_date").show();
                else if ($(this).val() == "dictselect")
                  tpw.find("#div_f_dictselect").show();
                else if ($(this).val() == "sqlselect")
                  tpw.find("#div_f_sqlselect").show();
                else if ($(this).val() == "tagselect")
                  tpw.find("#div_f_tagselect").show();
                else if ($(this).val() == "uddt")
                  tpw.find("#div_f_uddt").show();
                else if ($(this).val() == "d")
                  tpw.find("#div_f_d").show();
              }
            } else if (undefined != $(this).attr("ext"))
            {
              fValue = $(this).val();
              tpw.find("[ext='" + $(this).attr("ext") + "']").each(function ()
              {
                $(this).val(fValue);
              });
            } else if (undefined != $(this).attr("ctag"))
            {
              fValue = $(this).is(':checked');
              tpw.find("[ctag='" + $(this).attr("ctag") + "']").each(function ()
              {
                $(this).attr("checked", fValue);
              });
            }
          });
        });
      });
      $(document).on("click", "#fieldDel", function ()
      {
				if (getCheckedCount() <=0)
				{
					msgbox.alert({content:'没有选中要删#(jxrb.message("public.question,action.delete"))除的字段！'});
					return ;
				}
				msgbox.confirm({content:'#(jxrb.message("public.question,action.delete"))【选中的字段】吗?'},
				function()
				{
				  msgbox.close() ;
				  $("#fieldinfo_tab").find("[id='ck_field']").each(function()
          {
            if ($(this).is(":checked"))
            {
              var fieldid = $(this).parent().parent().find("[name='SRFI.id']").val() ;
              if (fieldid != "")
              {
                $.get("#(controllerKey)?html=fieldDel&paras=systemReportFieldInfo-" + fieldid,function(data)
                {
                  $("#div_delfield").append(data) ;
                }) ;
              }
              $(this).parent().parent().remove() ;
            }
          })
				},function(){}
				);

      });
      $(window.document).on("change", "#fieldType", function ()
      {
        fieldTypeChange($(this)) ;
      });
      $(window.top.document).on("change", "#fieldType", function ()
      {
        fieldTypeChange($(this)) ;
      });
	  
	  function fieldTypeChange(fieldTypeObject)
	  {
      initTpw();
        tpw.find("div").each(function ()
        {
          if (undefined != $(this).attr("id"))
            $(this).hide();
        });
        if ((fieldTypeObject.val() == "ldate") || (fieldTypeObject.val() == "sdate"))
          tpw.find("#div_f_date").show();
        else if (fieldTypeObject.val() == "dictselect")
          tpw.find("#div_f_dictselect").show();
        else if (fieldTypeObject.val() == "sqlselect")
          tpw.find("#div_f_sqlselect").show();
        else if (fieldTypeObject.val() == "tagselect")
          tpw.find("#div_f_tagselect").show();
        else if (fieldTypeObject.val() == "uddt")
          tpw.find("#div_f_uddt").show();
        else if (fieldTypeObject.val() == "d")
          tpw.find("#div_f_d").show();
	  }
    });

    function returnInfo()
    {
      location.href = "#(controllerKey)";
    }
    function clearForm()
    {
      var action = '#(action)';
      if (action == 'added')
      {
        $("#reportCode").val("");
        $("#reportName").val("");
      }
    }

    function createData()
    {
      var modelNum = 0;
      var modelFlag = 0;
      var fieldFlag = 0;
      var fieldExt = {};
      $("#fieldinfo_tab").find("tr").each(function ()
      {
        if ($(this).attr("class") != "title")
        {
          modelFlag = 0;
          fieldFlag = 0;
          fieldExt = {};
          $(this).find("input,textarea").each(function ()
          {
            if (modelFlag == 0)
              modelFlag = 1;
            else
              modelFlag = 2;
            if (undefined != $(this).attr("name"))
            {
              $(this).attr("name", $(this).attr("name").replace("SRFI", "systemReportFieldInfo[" + modelNum + "]"));
            }

            if (($(this).attr("ext") != undefined) && $(this).parent().is(":visible"))
              fieldExt[$(this).attr("ext")] = $(this).val();

            if ($(this).attr("id") == "fieldExt")
              $(this).val(JSON.stringify(fieldExt));

            if ($(this).attr("type") == "checkbox")
              if ($(this).is(':checked'))
                fieldFlag = fieldFlag | $(this).val();

            if ($(this).attr("id") == "fieldFlag")
              $(this).val(fieldFlag);
          });
          if (modelFlag > 0)
            modelNum++;

          $("#fieldCount").val(modelNum);
        }
      });

      if (modelNum == 0)
        return false;
      else
        return true;
    }
    
  });
</script>
#end
#define formBefore()
<nav class="navbar navbar-fixed-top">
<div style="margin-top:5px">
  #jx_button({value:"action.save"})
  #jx_button({value:"action.return",id:"b_return"})
  #jx_button({value:"action.add,字段",id:"fieldAdd",class:"btn btn-info"})
  #jx_button({value:"action.edit,字段",id:"fieldEdit",class:"btn btn-info"})
  #jx_button({value:"action.del,字段",id:"fieldDel",class:"btn btn-warning"})
  </div>
</nav>
<div style="margin-top:35px">
#end
#define form()
#include("info.html")
#end
</div>